'use strict';

const Controller = require('egg').Controller;
/**
 * @Controller Iterviewform
 */
class IterviewformController extends Controller {
    async index() {
        const ctx = this.ctx;
        try {
            const iterviewformList = await ctx.service.iterviewform.find(ctx.query);
            ctx.body = {
                code: 200,
                data: iterviewformList,
                success: true,
                msg: ``
            };
        }
        catch (err) {
            throw err;
        }
    }

    async create() {
        const ctx = this.ctx;

        try {
            const newIterviewform = await ctx.service.iterviewform.create(ctx.request.body);
            ctx.body = {
                code: 200,
                data: newIterviewform,
                success: true,
                msg: ``
            };
            console.log(newIterviewform);
        }
        catch (err) {
            throw err;
        }

    };
    async update() {
        const ctx = this.ctx;
        // ctx.validate(deleteRule, ctx.params);
        const result = await this.ctx.service.job.updateOneIterviewform({_id: ctx.params.id}, ctx.request.body);
        if(result.ok) {
            ctx.body = {
                code: 200,
                data: {},
                success: true,
                msg: `修改成功`
            }
        }
    }
    // 删除用户面试信息
    async destroy() {
        const ctx = this.ctx;
        // ctx.validate(deleteRule, ctx.params);
        const result = await this.ctx.service.iterviewform.deleteIterviewform(ctx.params.id);
        if(result.ok) {
            ctx.body = {
                code: 200,
                data: {},
                success: true,
                msg: `删除成功`
            }
        }
    }
}

module.exports = IterviewformController;
